<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\NodeModel;
use think\Db;
class Index extends Base
{
    public function index()
    {
        // 获取权限菜单
        $node = new NodeModel();
        $this->assign([
            'menu' => $node->getMenu(session('rule'))
        ]);
        return $this->fetch('/index');
    }

    /**
     * 后台默认首页
     * @return mixed
     */
    public function indexPage()
    {
        $this->assign('sys_info',$this->get_sys_info());
        $today = strtotime(date("Y-m-d"));

        $count['new_vip'] = $this->get_new_vip();//今天回收订单数
        $count['new_apply'] = $this->get_new_apply();//今天回收总重量
        $count['apply'] =  $this->get_apply_count();//积分兑换总数
        $count['order'] = $this->get_order_count();//订单总数
        $count['cash'] =  $this->get_cash_count();//提现总数
        $count['users'] = $this->get_users_count();//会员总数
        //$count['income'] = $this->get_income_count();//会员总数
        //$count['expend'] = $this->get_expend_count();//会员总数
        $this->assign('count',$count);
        return $this->fetch('index');
    }
    public function get_new_vip(){
        $result=Db::name('order')->where("type=0 AND pay_time>0 AND FROM_UNIXTIME(pay_time,'%Y-%m-%d')='".date('Y-m-d')."'")->count();
        return $result;
    }
    public function get_new_apply(){
        $result=Db::name('apply')->where("FROM_UNIXTIME(addtime,'%Y-%m-%d')='".date('Y-m-d')."'")->count();
        return $result;
    }
    public function get_apply_count(){
        $result=Db::name('apply')->count();
        return $result;
    }
    public function get_order_count(){
        $result=Db::name('order')->where("type=0 AND pay_status=1")->sum('money');
        return $result;
    }
    public function get_cash_count(){
        $result=Db::name('user_cash')->where("status=2")->sum('money');
        return $result;
    }
    public function get_users_count(){
        $result=Db::name('users')->count();
        return $result;
    }
    /*
    public function get_income_count(){
        $paidMoney=Db::name('order')->where(array('pay_status'=>1,"FROM_UNIXTIME(pay_time,'%Y-%m')"=>date('Y-m')))->sum('paid_money');
        $orderAmount=Db::name('order_pay')->where(array('pay_status'=>1,"FROM_UNIXTIME(pay_time,'%Y-%m')"=>date('Y-m')))->sum('order_amount');
        $payMoney=Db::name('recharge')->where(array('pay_status'=>1,'type'=>0,"FROM_UNIXTIME(pay_time,'%Y-%m')"=>date('Y-m')))->sum('pay_money');
        return $paidMoney+$orderAmount+$payMoney;
    }
    public function get_expend_count(){
        return Db::name('user_cash')->where(array('status'=>2,"FROM_UNIXTIME(check_time,'%Y-%m')"=>date('Y-m')))->sum('amount');
    }
*/
    public function get_sys_info(){
        $sys_info['os']             = PHP_OS;
        $sys_info['zlib']           = function_exists('gzclose') ? 'YES' : 'NO';//zlib
        $sys_info['safe_mode']      = (boolean) ini_get('safe_mode') ? 'YES' : 'NO';//safe_mode = Off
        $sys_info['timezone']       = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
        $sys_info['curl']			= function_exists('curl_init') ? 'YES' : 'NO';
        $sys_info['web_server']     = $_SERVER['SERVER_SOFTWARE'];
        $sys_info['phpv']           = phpversion();
        $sys_info['ip'] 			= GetHostByName($_SERVER['SERVER_NAME']);
        $sys_info['fileupload']     = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown';
        $sys_info['max_ex_time'] 	= @ini_get("max_execution_time").'s'; //脚本最大执行时间
        $sys_info['set_time_limit'] = function_exists("set_time_limit") ? true : false;
        $sys_info['domain'] 		= $_SERVER['HTTP_HOST'];
        $sys_info['memory_limit']   = ini_get('memory_limit');
        //$sys_info['version']   	    = file_get_contents(APP_PATH.'admin/conf/version.php');
        $sys_info['version']   	    = '';
        $mysqlinfo = Db::query("SELECT VERSION() as version");
        $sys_info['mysql_version']  = $mysqlinfo[0]['version'];
        if(function_exists("gd_info")){
            $gd = gd_info();
            $sys_info['gdinfo'] 	= $gd['GD Version'];
        }else {
            $sys_info['gdinfo'] 	= "未知";
        }
        return $sys_info;
    }
}